const path = require("path");
const fs = require("fs");

const { spawn } = require("child_process");

//linux下执行sh文件
const dirPath = path.resolve(__dirname);
const filePath = path.resolve(dirPath, `./vue-back.sh`);

// 检查文件是否存在
if (!fs.existsSync(filePath)) {
  console.log(filePath + "批处理文件不存在");
  return;
}

//使用spawn执行cmd文件
let child = spawn("sh", [filePath]);
let buffers = [];
child.stdout.on("data", function (buffer) {
  buffers.push(buffer);
});
child.stdout.on("end", function (buffer) {
  let logs = Buffer.concat(buffers).toString();
  console.log(logs);
  //   sendMail(`
  //       <h1>部署日期:${new Date()}</h1>
  //       <h2>部署人:${payload.pusher.name}</h2>
  //       <h2>部署邮箱:${payload.pusher.email}</h2>
  //       <h2>提交信息:${
  //         payload.head_commit && payload.head_commit["message"]
  //       }</h2>
  //       <h2>部署日志:${logs.replace("\r\n", "<br/>")}</h2>
  // `);
});
